<?php
header('Content-type:text/plain; charset=utf-8;');

ini_set('display_error', true);
ini_set('max_execution_time', 0);

error_reporting(E_ALL);

if($_SERVER['HTTP_X_ROUTE'] != true) die('No access');

#print_r($GLOBALS);

$request = json_decode($_POST['request'], true) or die('json_decode false');

#print_r($request);exit;

/* ----------------------------------------------------------------------------------------------------------------------- */

$ch = curl_init($request['__system__']['url']) or die(curl_error($ch));

if(!empty($request['__system__']['use_proxy']))
{
	curl_setopt($ch, CURLOPT_PROXY, $request['__system__']['proxy']);
}

if(!empty($request['__system__']['header']))
{
	curl_setopt($ch, CURLOPT_HTTPHEADER, $request['__system__']['header']);
}

if($request['__system__']['viewHeaders'])
{
	curl_setopt($ch, CURLOPT_HEADER, true);
}

if(!empty($request['post']))
{
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, (is_array($request['post']) ? $request['post'] : base64_decode($request['post'])));
}

if(!empty($request['__system__']['cookies']))
{
	curl_setopt($ch, CURLOPT_COOKIE, @implode(' ', unserialize(base64_decode($request['__system__']['cookies']))));
}

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8');

echo curl_exec($ch);

if(curl_errno($ch)) die(curl_error($ch));

curl_close($ch);

?>
